package cn.example.zjgsu.controller;

import cn.example.zjgsu.exception.MyException;
import cn.example.zjgsu.pojo.result.JsonData;
import cn.example.zjgsu.service.DiscoverPageServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: miaopeihan
 * @date: 2020-03-18  18:58
 */


@RestController
@RequestMapping({"/v1/api/discoverpage"})
@Api(description = "发现美食")
@CrossOrigin
public class DiscoverPageController {

    @Autowired
    DiscoverPageServer discoverPageServer;

   @ApiOperation("获取热门食记主页")
   @GetMapping(value = "/getPopularFoodRecord")
   public JsonData getPopularFoodRecord(){
       return JsonData.success(discoverPageServer.getPopularFoodRecord());
   }

    @ApiOperation("获取关注食记主页")
    @GetMapping(value = "/getFocusFoodRecord")
    public JsonData getFocusFoodRecord(@RequestParam String account) {
       try {
           return JsonData.success(discoverPageServer.getFocusFoodRecord(account));
       }catch (MyException e){
           return JsonData.fail(e.getMessage());
       }

    }

    @ApiOperation("增加食记浏览数")
    @PostMapping(value = "/addViews")
    public  void  addViews(int foodRecordId){
        discoverPageServer.addViews(foodRecordId);
    }
}
